#ifndef _HPCR_LOG_H_
#define _HPCR_LOG_H_
#include "hpcr_types.h"
#include <stdlib.h>

enum hpcr_log_level
{
    HPRC_LOG_LEVEL_INFO,
    HPRC_LOG_LEVEL_DEBUG,
    HPRC_LOG_LEVEL_WARNING,
    HPRC_LOG_LEVEL_ERROR
};

#ifndef _DEFINE_HPCR_LOG_MAX_LEN_
#define _DEFINE_HPCR_LOG_MAX_LEN_ 1024
#endif

#ifndef _DEFINE_HPCR_LOG_OUTPUT_FD_
#define _DEFINE_HPCR_LOG_OUTPUT_FD_ 1
#endif

typedef enum hpcr_log_level hpcr_log_level_t;

void hpcr_log(char *message, char *file, int line, hpcr_log_level_t level);

#define LOG(message, LOG_LEVEL) hpcr_log(message, __FILE__, __LINE__, LOG_LEVEL)

#define INFO(message) LOG(message, HPRC_LOG_LEVEL_INFO)
#define DEBUG(message) LOG(message, HPRC_LOG_LEVEL_DEBUG)
#define WARNING(message) LOG(message, HPRC_LOG_LEVEL_WARNING)

#define assert(condition)                          \
    do                                             \
    {                                              \
        if (!(condition))                          \
        {                                          \
            LOG(#condition, HPRC_LOG_LEVEL_ERROR); \
            perror("assert");                      \
            exit(0);                               \
        }                                          \
    } while (0)

#endif